
import {throttle} from "miniprogram-licia"

Page({
  data:{
    visitorList:[],
    pageTotal:"",
    total:""
  },
  goPassport(ev) {
    console.log(this.data);
    if (this.data.visitorList.filter((word) => word.status === 1).map(item => item.id).includes(ev.mark.id) ) {
      wx.navigateTo({
        url: '/visitor_pkg/pages/passport/index?id='+ev.mark.id,
      })
    }else{
      return wx.utils.toast("当前状态已过期！")
    }
  
  },
  onLoad(){

    this.visitorInfoList()

    this.getMoreVisitor = throttle(()=>{
      console.log(111);
      if (this.data.isMore)  return 
      this.visitorInfoList(++this._current)
    },100)
  },
  // 获取访客列表
  async visitorInfoList(current = 1,pageSize = 5){
    // if (current > this.data.pageTotal) {
    //   return false
    // }
    const res =  await wx.myRequest.get("/visitor",{
      current,pageSize
    })
    this.setData({
      isMore: current >= res.data.pageTotal,
      visitorList:this.data.visitorList.concat(res.data.rows),
      isEmpty:res.data.length === 0
    })

    this._current = current
  }
})
